package com.sg.business.commons.labelprovider.user;

import org.bson.types.ObjectId;

import com.mobnut.db.model.ModelService;
import com.sg.business.model.User;
import com.sg.business.model.toolkit.UserToolkit;
import com.sg.widgets.commons.labelprovider.ConfiguratorColumnLabelProvider;

public class UserIdLabel extends ConfiguratorColumnLabelProvider {

	@Override
	public String getText(Object element) {
		Object value = getValue(element);
		if (value instanceof String) {
			User user = UserToolkit.getUserById((String) value);
			if (user != null) {
				return user.getLabel();
			} else {
				return "?"; //$NON-NLS-1$
			}
		}
		if (value instanceof ObjectId) {
			ObjectId id = (ObjectId) value;
			User user = ModelService.createModelObject(User.class, id);
			
			if (user != null) {
				return user.getLabel();
			} else {
				return "?"; //$NON-NLS-1$
			}
		}
		return ""; //$NON-NLS-1$
	}
}
